/**
 * 七牛图片
 *
 * @author xiaomi
 */

import qnUrl from './qn-url';

export default function(url, width, height, type) {
    // clean
    url = url.replace(/\?imageView.+$/, '');

    // not support img, eg. svg
    if(/\.svg$/.test(url)) {
        return url;
    }

    var params = '';

    if(width || height) {
        type = type || 2;

        params += 'imageView2/' + type;
    }

    if(height === null && width) {
        height = width;
    }
    if(width) {
        params += '/w/' + width;
    }
    if(height) {
        params += '/h/' + height;
    }

    return qnUrl(url, params);
};
